package com.jdjw.modules.migranttasksign.service.impl;

import com.jdjw.common.ResponseResult;
import com.jdjw.modules.migranttasksign.entity.MigrantTaskSign;
import com.jdjw.modules.migranttasksign.entity.MigrantTaskSignVo;
import com.jdjw.modules.migranttasksign.mapper.MigrantTaskSignMapper;
import com.jdjw.modules.migranttasksign.service.MigrantTaskSignService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 务工发布表 服务实现类
 * </p>
 *
 * @author fq
 * @since 2021-07-28
 */
@Service
public class MigrantTaskSignServiceImpl extends ServiceImpl<MigrantTaskSignMapper, MigrantTaskSign> implements MigrantTaskSignService {

    @Autowired
    private MigrantTaskSignMapper migrantTaskSignMapper;
    
    @Override
    public ResponseResult queryAll(MigrantTaskSignVo migrantTaskSignVo) {
        ResponseResult rrt=new ResponseResult();
        try {
            int start=migrantTaskSignVo.getPage()*migrantTaskSignVo.getRow()-migrantTaskSignVo.getRow();
            migrantTaskSignVo.setPage(start);
            String[] arr = migrantTaskSignVo.getUserName().split("");
            String role = arr[arr.length - 1];
            /** 如果是村 **/
            if (role.equals("村") || role.equals("区")) {
                migrantTaskSignVo.setUserName("1");
            } else {
                migrantTaskSignVo.setUserName("0");
            }
            List<MigrantTaskSign> migrantTaskSigns = migrantTaskSignMapper.queryAll(migrantTaskSignVo);
            rrt.setMsg("查询成功");
            rrt.setCode(200);
            rrt.setData(migrantTaskSigns);
        } catch (Exception e) {
            e.printStackTrace();
            rrt.setCode(500);
            rrt.setMsg("查询异常"+e.getMessage());
            rrt.setData(null);
        }
        return rrt;
    }

    @Override
    public ResponseResult edit(String sqlEdit) {
        ResponseResult rrt=new ResponseResult();
        try {
            Boolean edit = migrantTaskSignMapper.edit(sqlEdit);
            rrt.setMsg("编辑成功");
            rrt.setCode(200);
        } catch (Exception e) {
            e.printStackTrace();
            rrt.setMsg("编辑失败"+e.getMessage());
            rrt.setCode(500);
        }
        return rrt;
    }

    @Override
    public ResponseResult queryAllList(MigrantTaskSignVo migrantTaskSignVo) {
        return null;
    }

    @Override
    public void insertMigrantTaskWorkerInfo(Map<String, Object> param) {

    }

    @Override
    public List<Map<String, Object>> queryMigrantInfoByTaskId(Map<String, Object> param) {
        return null;
    }
}
